home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Support / BCDynami.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  2.5 KB  |  90 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  BCDynami.h
  5. //
  6. //  This file contains the declaration of the dynamic array-based class
  7. //  used for the representation of dynamic structures.
  8.  
  9. #ifndef BCDYNAMI_H
  10. #define BCDYNAMI_H 1
  11.  
  12. #include <stddef.h>
  13. #include "BCExcept.h"
  14.  
  15. // Class denoting an optimally-packed dynamic container
  16.  
  17. template<class Item, class StorageManager>
  18. class BC_TDynamic {
  19. public:
  20.  
  21.   BC_TDynamic();
  22.   BC_TDynamic(BC_Index chunkSize);
  23.   BC_TDynamic(const BC_TDynamic<Item, StorageManager>&);
  24.   ~BC_TDynamic();
  25.  
  26.   BC_TDynamic<Item, StorageManager>&
  27.     operator=(const BC_TDynamic<Item, StorageManager>&);
  28.   BC_Boolean operator==(const BC_TDynamic<Item, StorageManager>&) const;
  29.   BC_Boolean operator!=(const BC_TDynamic<Item, StorageManager>& c) const
  30.     {return !operator==(c);}
  31.   const Item& operator[](BC_Index index) const
  32.     {BC_Assert((index < Length()),
  33.                BC_XRangeError("BC_TDynamic<>::operator[]", BC_kInvalidIndex));
  34.      return ItemAt(index);}
  35.   Item& operator[](BC_Index index)
  36.     {BC_Assert((index < Length()),
  37.                BC_XRangeError("BC_TDynamic<>::operator[]", BC_kInvalidIndex));
  38.      return ItemAt(index);}
  39.  
  40.   void SetChunkSize(BC_Index chunkSize)
  41.     {BC_Assert((!fChunkSize),
  42.                BC_XNotNull("BC_TDynamic<>::SetChunkSize", BC_kNotEmpty));
  43.      fChunkSize = chunkSize;}
  44.   void Preallocate(BC_Index newLength);
  45.   void Clear();
  46.   void Insert(const Item&);
  47.   void Insert(const Item&, BC_Index before);
  48.   void Append(const Item&);
  49.   void Append(const Item&, BC_Index after);
  50.   void Remove(BC_Index at);
  51.   void Replace(BC_Index at, const Item&);
  52.  
  53.   BC_Index ChunkSize() const
  54.     {return fChunkSize;}
  55.   BC_Index Length() const;
  56.   const Item& First() const
  57.     {return fRep[fStart - 1];}
  58.   Item& First()
  59.     {return fRep[fStart - 1];}
  60.   const Item& Last() const
  61.     {return fRep[fStop - 1];}
  62.   Item& Last()
  63.     {return fRep[fStop - 1];}
  64.   const Item& ItemAt(BC_Index) const;
  65.   Item& ItemAt(BC_Index);
  66.   BC_ExtendedIndex Location(const Item&, BC_Index start = 0) const;
  67.  
  68.   static void* operator new(size_t);
  69.   static void operator delete(void*, size_t);
  70.  
  71. protected:
  72.  
  73.   Item* fRep;
  74.   BC_Index fSize;
  75.   BC_Index fTotalChunks;
  76.   BC_Index fChunkSize;
  77.   BC_Index fStart;
  78.   BC_Index fStop;
  79.   
  80.   void Resize(BC_Index currentLength, BC_Index newLength, BC_Boolean preserve = 1);
  81.  
  82.   BC_Index ExpandLeft(BC_Index from);
  83.   BC_Index ExpandRight(BC_Index from);
  84.   void ShrinkLeft(BC_Index from);
  85.   void ShrinkRight(BC_Index from);
  86.   
  87. };
  88.  
  89. #endif
  90.